import * as consts from './const'
import axios from '../http'

export default {
  // 获取分类列表
  getCatalogs(type, callback) {
    var url = ''
    if (type == consts.CATALOG_TYPE_QUESTION) {
      url = '/dianping/catalog/?limit=30'
    } else if (type == consts.CATALOG_TYPE_MASTER) {
      url = '/users/catalog/?limit=30'
    } else if (type == consts.CATALOG_TYPE_PAINTING) {
      url = '/works/catalog/?limit=30'
    } else if (type == consts.CATALOG_TYPE_NEWS) {
      url = '/news/catalog/?limit=30'
    }
    // 调用登陆接口
    axios.get(url)
    .then(function (res) {
      if (res.status === 200) {
        return callback(null, res.data)
      } else {
        return callback(res)
      }
    })
    .catch(function (error) {
      return callback(error)
    })
  },

  getLevels(callback) {
    var url = '/users/masterlevel/'
    // 调用登陆接口
    axios.get(url)
    .then(function (res) {
      if (res.status === 200) {
        return callback(null, res.data)
      } else {
        return callback(res)
      }
    })
    .catch(function (error) {
      return callback(error)
    })
  }
}
